## Table 3: Effects of Differential Demand on Wait Times: Across Cities, Within Common Service

## install.packages(c("tidyverse", "fixest"))
## library(tidyverse)
## library(fixest)

## SET WORKING DIRECTORY HERE
## setwd()

## Loading data
## load("demand_common_services.RData")

## Column 1
race_wait_demand <- feols(log_norm_mean_wait ~ non_white_demand |
                            common_service^open_month^open_year, 
                          data = demand_common_services, 
                          weights = demand_common_services$tot_calls,
                          cluster = "city_common_service")

## Column 2
race_wait_need <- feols(log_norm_mean_wait ~ non_white_need |
                          common_service^open_month^open_year, 
                        data = demand_common_services, 
                        weights = demand_common_services$tot_calls,
                        cluster = "city_common_service")

## Column 3
income_wait_demand <- feols(log_norm_mean_wait ~ poor_demand |
                              common_service^open_month^open_year, 
                            data = demand_common_services, 
                            weights = demand_common_services$tot_calls,
                            cluster = "city_common_service")

## Column 4
income_wait_need <- feols(log_norm_mean_wait ~ poor_need |
                            common_service^open_month^open_year, 
                          data = demand_common_services, 
                          weights = demand_common_services$tot_calls,
                          cluster = "city_common_service")

## Column 5
race_expected_demand <- feols(log_norm_mean_expected ~ non_white_demand |
                                common_service^open_month^open_year, 
                              data = demand_common_services, 
                              weights = demand_common_services$tot_calls,
                              cluster = "city_common_service")

## Column 6
race_expected_need <- feols(log_norm_mean_expected ~ non_white_need |
                              common_service^open_month^open_year, 
                            data = demand_common_services, 
                            weights = demand_common_services$tot_calls,
                            cluster = "city_common_service")

## Column 7
income_expected_demand <- feols(log_norm_mean_expected ~ poor_demand |
                                  common_service^open_month^open_year, 
                                data = demand_common_services, 
                                weights = demand_common_services$tot_calls,
                                cluster = "city_common_service")

## Column 8
income_expected_need <- feols(log_norm_mean_expected ~ poor_need |
                                common_service^open_month^open_year, 
                              data = demand_common_services, 
                              weights = demand_common_services$tot_calls,
                              cluster = "city_common_service")

Table3 = etable(race_wait_demand, race_wait_need, 
              income_wait_demand, income_wait_need,
              race_expected_demand, race_expected_need,
              income_expected_demand, income_expected_need,
              signifCode = c("+" = 0.10, "*" = 0.05, "**" = 0.01, "***" = 0.001),
              digits = 3, digits.stats = 3, fitstat =c("n","r2"))